import requests
from config.Configuration import host_port

#使用单例模式 结果重复登录获取sessionid的问题
class GetSession:
    #使用静态属性用例保存生成的会话
    s = None

    @classmethod
    def get_session(cls):
        if cls.s == None:
            cls.s = requests.Session()
            #调用登录方法，会自动将sessionid存储到会话中
            GetSession.login()

        return cls.s

    @classmethod
    def login(cls):
        url = f"http://{host_port}/WoniuBoss4.0/login/userLogin"
        headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
        payload = {'userName':'WNCD000','userPass':'woniu123','checkcode':'0000','remember':'Y'}
        cls.s.post(url, headers=headers, data=payload)